<?php

use yii\db\Migration;

class m000000_000020_create_article_view_log extends Migration
{
    public function up()
    {
        $this->createTable('{{%article_view_log}}', [
            'id'=>$this->primaryKey(), // PK
            'uid'=>$this->integer(), // 用户编号
            'sid'=>$this->string(64), // SESSIONID
            'aid'=>$this->integer(), // 资讯编号
            'ip'=>$this->string(32), // IP地址
            'time'=>$this->integer(), // 访问时间
        ]);
        $this->createIndex('fk_article_view_log_user1_idx', '{{%article_view_log}}', ['uid']);
        try {
            $this->addForeignKey('fk_article_view_log_user1', '{{%article_view_log}}', ['uid'], '{{%user}}', ['id']);
        } catch (Exception $e) {
        }
        $this->createIndex('fk_article_view_log_article1_idx', '{{%article_view_log}}', ['aid']);
        try {
            $this->addForeignKey('fk_article_view_log_article1', '{{%article_view_log}}', ['aid'], '{{%article}}', ['id']);
        } catch (Exception $e) {
        }
    }

    public function down()
    {
        $this->dropTable('{{%article_view_log}}');
    }
}
